package com.itheima.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.entity.Category;
import com.itheima.mapper.CategoryMapper;
import com.itheima.service.ICategoryService;
import com.itheima.util.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;

@Slf4j
@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements ICategoryService {

    @Resource
    private CategoryMapper categoryMapper;
    @Resource
    private StringRedisTemplate stringRedisTemplate;

    /**
     * 添加类型
     * @param category 需要添加的套餐详情
     * @return：   返回是否添加成功
     */
    @Override
    public Result addCategory(Category category) {

        int r = categoryMapper.insert(category);
        if (r<=0){
            return Result.error("添加失败");
        }
        return Result.success(category);
    }

    @Override
    public Result updateCategory(Category category) {
        categoryMapper.updateById(category);
        return Result.success("修改分类信息成功");
    }

    @Override
    public Result seleteList() {


        return Result.success(categoryMapper.selectList(null));
    }

    @Override
    public IPage getPage(int current, int pageSize) {
        IPage<Category> page = new Page<Category>(current,pageSize);
        return categoryMapper.selectPage(page,null);
    }
}
